#include <iostream>
#include <unistd.h>
#include <sys/types.h>
using namespace std;

__thread int g_val = 100;
__thread pid_t lwp = 0;
void *ThreadRoutine(void *args)
{
    string name = static_cast<const char*>(args);
    lwp = gettid();
    while(1)
    {
        g_val ++;
        cout << name << ' ' << "g_val=" << g_val  << ' ' << "&g_val=" << &g_val << endl;
        cout << "lwp=" << lwp << endl;
        cout << endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, ThreadRoutine, (void*)"Thread1");
    lwp = gettid();
    sleep(0.5);
    while(1)
    {
        
        cout << "main:" << ' ' << "g_val=" << g_val << ' ' << "&g_val=" << &g_val << endl;
        cout << "lwp=" << lwp << endl;
        cout << endl;
        sleep(1);
    }
    pthread_join(tid, nullptr);
    return 0;
}